/* 
 * File:   PilhaClient.hpp
 * Author: Ana Paula
 *
 * Created on 14 de Julho de 2011, 17:49
 */

#ifndef PILHACLIENT_HPP
#define	PILHACLIENT_HPP

#include <list>
#include <iostream>

class PilhaClient /*: public Pilha */ {

    public :

        PilhaClient() {

            this->buf = new std::list<char>();
        };

        ~PilhaClient() {};

        void escreve(int dest, int tam, unsigned char* data) {

            std::cout << "Escrevendo mensagem C" << this->link << std::endl;
            for (int i = 0; i < tam; i++) {

                std::cout << "Mensagem: " << data[i] << std::endl;
                this->link->buf->push_back(data[i]);
                std::cout << "After: " << this->link->buf->front() << std::endl;
            }
        };

        void le(unsigned char* b, unsigned int t) {

            //std::cout << "Size: " << this->buf->size() << " Tam: " << t << std::endl;
            while (t > this->buf->size());

            for (int i = 0; i < t; i++) {

               // std::cout << "Lendo mensagem C" << this->id <<std::endl;
                b[i] = this->buf->front();
                this->buf->pop_front();
            }

        };

        void close() {};

    //private :

        PilhaClient* link;
        std::list<char>* buf;
};

#endif	/* PILHACLIENT_HPP */

